package com.hyz.login.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyz.login.model.Pay;
import com.hyz.login.model.Register;
import com.hyz.login.service.PayService;
import com.hyz.login.service.RegisterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwq
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/page")
public class PayController {

    Logger logger = LoggerFactory.getLogger(PayController.class);

    @Autowired
    private PayService payService;
    @Autowired
    private RegisterService registerService;

    @GetMapping("/liao/selPays")
    public String selPays(Integer registerid, Integer page, Integer limit){
        IPage<Pay> iPage =payService.findAll(registerid, page, limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }

    @PostMapping("/liao/selPay")
    public Register registerid(Register register,Integer moneys){
        if (moneys!=null && moneys != 0){
            payService.addPay(register.getRegisterid(),moneys);
            registerService.modifyMoney(register.getRegisterid(),moneys);
        }
        return registerService.findById(register.getRegisterid());
    }
}

